package com.lagou.edu.factory.scanner.impl;


import com.lagou.edu.factory.scanner.Matcher;

import java.lang.annotation.Annotation;
import java.util.stream.Stream;

public class TypeAnnotationMatcher implements Matcher {


    private Class<?> annotationClass;


    public TypeAnnotationMatcher(Class<?> annotationClass) {
        this.annotationClass = annotationClass;
    }

    /**
     * 判断给定的类是否匹配
     * @param clz 给定的类
     * @return 匹配结果
     */
    @Override
    public boolean isMatch(Class<?> clz) {
        Annotation[] annotations = clz.getAnnotations();
        return Stream.of(annotations).anyMatch(e -> e.annotationType() == annotationClass);
    }
}